var j$ = jQuery.noConflict();

j$(document).ready(function () {

    /* UI -------------------------------- */
    // todo textarea
    /* text */
    j$(document).on({
        "focus":function(){
            j$(this).parent(".text-con").addClass("text-focus");
        },
        "blur":function(){
            j$(this).parent(".text-con").removeClass("text-focus");
        }
    },".text-input");

    j$(document).on({
        "focus":function(){
            j$(this).addClass("text-focus");
        },
        "blur":function(){
            j$(this).removeClass("text-focus");
        }
    },".text, .textarea");

    /* select */
    
    j$(document).on("click", ".select-show", function () {
        var select = j$(this).closest(".select-con"),
            list = select.find(".select-list"),
            isOpen = list.hasClass("db");
        if (select.hasClass("select-disable")) {
            return;
        }
        // select closed
        j$(".select-list").removeClass("db");
        j$(".select-con").removeClass("select-focus");
        // select open
        if (!isOpen) {
            list.addClass("db");
            select.addClass("select-focus");
        }
    }).on("click", ".select-option", function () {
            var select = j$(this).closest(".select-con");
            select.find(".select-text").text(j$(this).text());
            select.find("input").val(j$(this).attr("data-value"));
            // select closed
            select.find(".select-list").removeClass("db");
            select.removeClass("select-focus");

            var inputid = select.find(".select-show").attr('id');
            TabFoucs(inputid);

        });

    j$(document).on("click", function (e) {
        var heNode = j$(e.target).closest(".select-con");
        var heNode2 = j$(e.target).closest(".select_results");

        // select closed
        if (heNode.length == 0 && heNode2.length == 0) {
            j$(".select-list").removeClass("db");
            j$(".select-con").removeClass("select-focus");
        }
    });

    // j$(document).on("click","#city_name,#001,#city_name1,#002,#basicExample input",function (e) {
    //         j$(".select-list").removeClass("db");
    //         j$(".select-con").removeClass("select-focus");
   
    // });


    /* placeholder ----------------------------------------- */
    function placeholder(inputs) {
		inputs.each(function(i,e){
			var input = j$(e),
				text = input.prop("placeholder"),
				id = input.prop("id"),
				isPlaceholder = "placeholder" in document.createElement("input");

			if(!isPlaceholder){
				if(!id){
					id = "placeholder" + Math.random();
					input.prop("id", id);
				}

				var label = j$("<label for='" + id + "'class='text-label'></label>").insertAfter(input).text(text);
				input.on({
					"focus": function() {
						label.html("");
					},
					"blur": function() {
						if (input.val() === "") {
							label.html(text);
						}
					}
				});
				
				if(input.val() !== ""){
					label.html("");
				}
			}
		});

        // todo text-place; textarea
    }
    placeholder(j$(".text-search .text-input"));

});


